package SpringFramework.SpringProfile;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import SpringFramework.SpringProfile.config.JavaConfig;
import SpringFramework.SpringProfile.service.DemoBean;


public class Main {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context1 = null;
		AnnotationConfigApplicationContext context2 = null;
		try {
			context1 = new AnnotationConfigApplicationContext();
			context1.getEnvironment().setActiveProfiles("development");
			context1.register(JavaConfig.class);
			context1.refresh();
			
			context2 = new AnnotationConfigApplicationContext();
			context2.getEnvironment().setActiveProfiles("production");
			context2.register(JavaConfig.class);
			context2.refresh();
			
			DemoBean bean1 = context1.getBean(DemoBean.class);
			System.out.println("context1：" + bean1.getContent());
			
			DemoBean bean2 = context2.getBean(DemoBean.class);
			System.out.println("context2：" + bean2.getContent());
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if(context1!=null) {
				context1.close();
			}
			if(context2!=null) {
				context2.close();
			}
		}
	}

}
